package com.xingyun.info_manager.config;

import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Classname SecurityInterceptor
 * @Description 拦截器
 * @Date 2020/5/23 8:42
 * @Created by You
 */
public class SecurityInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws IOException {
        HttpSession session = request.getSession();
        System.out.println("这是路径地址："+request.getRequestURI());

        //判断是否已有该用户登录的session
        if(session.getAttribute("admin") != null){
            System.out.println("session存在用户信息");
            return  true;
        }else {
            System.out.println("没有session");
            response.sendRedirect("/info_manager/login.html");
            return false;
        }
    }
}
